/*
* Copyright (C) 2010, Jared Jennings <jaredljennings@gmail.com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
namespace org.jaredjennings.mysshmenu
{
	public partial class AddServer : Gtk.Window
	{
		StoreBackend sb = StoreBackend.GetInstance();		
		protected virtual void OnClicked_Save (object sender, System.EventArgs e)
		{
			Logger.Debug("Add Server", "Calling method to save entry");
			HostObj host = new HostObj();
			host.NAME = entry_server_name.Text;
			host.ADDRESS = entry_server_address.Text;
			host.PORT = entry_server_port.Text;
			Logger.Debug ("Add Server", " Saving : " + host.NAME + " - " + host.ADDRESS);
			host.CONNTYPE = (ConnectionType) Enum.Parse(typeof(ConnectionType), combobox_server_type.ActiveText, true);
			sb.addTo(host);
			this.Hide();			
		}
		
		
		public AddServer () : base(Gtk.WindowType.Toplevel)
		{
			this.Build ();
		}
		protected virtual void OnClicked_Cancel (object sender, System.EventArgs e)
		{
			this.Hide();
		}
		
		protected virtual void OnChanged_ConnType (object sender, System.EventArgs e)
		{
			Gtk.ComboBox tb = (Gtk.ComboBox)sender;
			Console.WriteLine ("combobox length {0}", tb.ActiveText.Length);
            if (util.Utils.isEmpty(tb.ActiveText)) return;
			
            switch (tb.ActiveText)
            {
                case "SSH":
                    entry_server_port.Text = "22";
                    break;
                case "RDP":
                    entry_server_port.Text = "3389";
                    break;
                case "VNC":
                    entry_server_port.Text = "5901";
                    break;				
            }			
		}
	}
}

